package chelydra.sharelydra.server.web.service;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import chelydra.sharelydra.server.web.SLSServlet;
import chelydra.sharelydra.server.ejb.SLSUser;
import java.util.Collection;
import java.util.StringTokenizer;
import java.util.Vector;

/**
 *
 * @author scallion
 */
public class SLSNotifyServlet extends SLSServlet {

	public SLSNotifyServlet() {
		this.action_name = "notify";
	}

	@Override
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
		this.initManager(request);
		SLSUser user=this.initAttributes(request,response);
		
		if (user!=null) {
			String file = request.getParameter("file");
			String friends = request.getParameter("friends");
			Collection<String> friendLogins = new Vector();

			StringTokenizer st =new StringTokenizer(friends,"<=>");
			while (st.hasMoreTokens()){
				friendLogins.add(st.nextToken());
			}

			this.manager.notifyUsersForFile(user, file, friendLogins);
		}

		this.rd.forward(request, response);
  }
}
